package common.hibernate.vo;

import java.util.List;
import java.util.Map;


public class Page<T> {
	private int total;
	private int totalPage ;
	private int currentPage;
	private int pageSize;
	private int start;// 当前页起始行
	private int end;// 结束行

	private List<T> rows;
	
	private List<Map<String, Object>> footer;

	public int getCurrentPage() {
		return currentPage;
	}

	public int getEnd() {
		return end;
	}


	public int getPageSize() {
		return pageSize;
	}

	public int getStart() {
		return start;
	}

	public int getTotal() {
		return total;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage < 1) {
			currentPage = 1;
        } else {
            start = pageSize * (currentPage - 1);
        }
        end = start + pageSize > total ? total : start + pageSize;
        this.currentPage = currentPage;
	}

	public void setEnd(int end) {
		this.end = end;
	}


	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public void setTotal(int total) {
		totalPage = (total + pageSize - 1) / pageSize;
        this.total = total;
        if (totalPage < currentPage && totalPage > 0) {
        	currentPage = totalPage;
            start = pageSize * (currentPage - 1);
            end = total;
        }
        end = start + pageSize > total ? total : start + pageSize;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public List<Map<String, Object>> getFooter() {
		return footer;
	}

	public void setFooter(List<Map<String, Object>> totalMapList) {
		this.footer = totalMapList;
	}
}
